<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button>传统注册</button>
    <button>方法监听注册事件</button>
    <button>attachEvent</button>
    <script>
        var btns = document.querySelectorAll('button')
        // 1.传统注册删除事件方法 this.onclick = null
        btns[0].onclick = function () {
            alert('传统')
            this.onclick = null
        }
        // 2.removeEventListener 删除事件 
        btns[1].addEventListener('click', fn);//里面的fn函数调用为特殊情况不需要加() 
        function fn() {
            alert('添加监听事件')
            this.removeEventListener('click', fn)
        }
    </script>
</body>

</html>